<?php
/**
 * Form View for JForms Component
 *
 * @version		$Id: view.html.php 150 2009-05-06 11:26:11Z dr_drsh $
 * @package		Joomla
 * @subpackage	JForms
 * @copyright	Copyright (C) 2008 Mostafa Muhammad. All rights reserved.
 * @license		GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

/**
 * Form View
 *
 * @package    Joomla
 * @subpackage JForms
 */
class FrontendViewForm extends JView {

    function display_thank( $form , $tpl = null ) {

        $document =& JFactory::getDocument();
        $document->addStyleSheet(JURI::base().'components/com_electroforms/views/form/'.$form->theme.'.css');

        $this->assignRef('form', $form );

        //Display the template
        parent::display($tpl);

    }

    /**
     * Form view display method
     *
     * Displays requested form
     *
     * @return void
     **/
    function display($form, VA_Form_Form $jform = null, $tpl = null) {
        global $JFormGlobals,$Itemid;

        /* @var $document JDocument */
        $document = JFactory::getDocument();
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.validate.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.noconflict.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.translations.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.form.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.metadata.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/jquery.ui.js');
        $document->addScript(JURI::base().'components/com_electroforms/views/form/js/init.validate.js');


//    $document->addStyleSheet(JURI::base().'components/com_electroforms/views/form/'.$form->theme.'.css');
        $document->addStyleSheet(JURI::base().'components/com_electroforms/views/form/reset.style.css');
        $document->addStyleSheet(JURI::base().'components/com_electroforms/views/form/jquery.ui.css');

        $pManager =& $JFormGlobals['JFormsPlugin'];

        //Load Element Plugins
        $pManager->loadElementPlugins();

        $jsCode = '';
        $jsValidationFunction = '';
        $jsClearErrorFunction = '';

        foreach( $form->fields as $f ) {
            $jsClearErrorFunction .= $pManager->invokeMethod('jsClearErrors', JFORM_PLUGIN_ELEMENT,
                    array($f->type), array( $f ) ) . "\n";

            $jsValidationFunction .= $pManager->invokeMethod('jsValidation', JFORM_PLUGIN_ELEMENT,
                    array($f->type), array( $f ) ) . "\n";
        }

        $id=$form->id;

        $user   =& JFactory::getUser();

        $this->assignRef('row'     , $form );
        $this->assignRef('jform'   , $jform );
        $this->assignRef('pManager', $pManager );
        $this->assignRef('uid'     , $user->id );
        $this->assignRef('Itemid'  , $Itemid );

        //Display the template
        parent::display($tpl);
    }

}